<template>
  <div class="bianji">
    <div class="wrap">
      <div class="title1">编辑推荐</div>
      <div class="content">
        <van-row gutter="2">
          <van-col
            span="8"
            v-for="item in list"
            :key="item.id"
            @click="selectItem(item)"
          >
            <div class="item">
              <img :src="item.picUrl" alt="" />
              <div class="total">{{ item.playCount | numFilter }}万</div>
              <div class="info">
                {{ item.name }}
              </div>
            </div>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="main">
      <div class="title1">最新音乐</div>
      <div class="list">
        <div class="item1" v-for="item in newsong" :key="item.id" @click="selectItem1(item)">
          <div class="left">
            <div class="subtitle">
              {{ item.name }}<span>{{ item.song.alias[0] }}</span>
            </div>
            <div class="author">
              <span v-for="ele in item.song.artists" :key="ele.id" class="ele">
                {{ ele.name }}</span
              >
              - {{ item.name }}
            </div>
          </div>
          <div class="right">
            <img
              src="../../assets/播放.svg"
              alt=""
              width="22px"
              height="22px"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      newsong: [],
    };
  },
  created() {
    this.getMusic();
    this.getNewSong();
  },
  methods: {
    getMusic() {
      this.$request("get", "personalized?limit=6").then((res) => {
        console.log(res.result);
        this.list = res.result;
      });
    },
    getNewSong() {
      this.$request("get", "/personalized/newsong").then((res) => {
        console.log(res.result);
        this.newsong = res.result;
      });
    },
    selectItem(item) {
      const id = item.id;
      console.log(id);
      this.$router.push({ path: `/playlist/${id}` });
    },
    selectItem1(item) {
      const id = item.id;
      console.log(id);
      this.$router.push({ path: `/song/${id}` });
    },
  },

  filters: {
    // 处理播放量的显示格式
    /**
     * param num ：小数位固定的位数
     * param value : 处理的数值
     */
    numFilter(value, num) {
      // 把小数位固定为num位
      return parseFloat(value / 10000).toFixed(num);
    },
  },
};
</script>
<style lang="less" scoped>
.title1 {
  font-size: 20px;
  text-align: left;
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
  font-size: 0.34rem;
  position: relative;
  padding-left: 0.5rem;
  &::before {
    content: "";
    position: absolute;
    width: 2px;
    height: 15px;
    top: 1px;
    background: #ff5555;
    left: 0;
  }
}
.content .item {
  position: relative;
}
.content .item img {
  width: 100%;
}
.content .item .total {
  color: #fff;
  position: absolute;
  right: 2px;
  top: 2px;
}
.content .item .info {
  height: 32px;
  font-size: 3px;
  margin: 0.16rem;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-align: left;
}

//最新音乐
.item1 {
  border-bottom: 1px solid #eee;
  padding-left: 10px;
  padding-top: 6px;
  padding-bottom: 6px;
  padding-right: 10px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.item1 .subtitle {
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}
.item1 .author {
  font-size: 12px;
  color: #888;

  margin-top: 4px;
}
.item1 .author .ele {
  &::after {
    content: " /";
  }
}
.item1 .author .ele:last-child {
  &::after {
    content: "";
  }
}
.item1 .subtitle span {
  color: #888;
}
.item1 .left {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}
.item .right > img {
  width: 22px;
  height: 22px;
}
</style>